import 'package:flutter/material.dart';
import 'package:intl/intl.dart';


class DateTimeDemo extends StatefulWidget {
  const DateTimeDemo({super.key});

  @override
  State<DateTimeDemo> createState() => _DateTimeDemoState();
}

class _DateTimeDemoState extends State<DateTimeDemo> {

  DateTime selectedDate = DateTime.now();
  TimeOfDay selectTime = const TimeOfDay(hour: 0, minute: 0);

 Future<void> _selectDate() async {
    final DateTime? date = await showDatePicker(
      context: context,
      initialDate: selectedDate,
      firstDate: DateTime(1900),
      lastDate: DateTime(2100),
      locale: const Locale('zh'),
    );

    if (date == null) {
      debugPrint('date kong');
    }else{
      setState(() {
        selectedDate = date;
      });
    }
    
  }

 Future<void> _selectTime() async {
    final TimeOfDay? time = await showTimePicker(
      context: context,
      initialTime: selectTime,
    );

    if (time == null) {
      debugPrint('time kong');
    } else {
      setState(() {
        selectTime = time;
      });
    }
    
  }

  

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('DateTimeDemo'),
        elevation: 0,
      ),
      body: Container(
        padding: const EdgeInsets.all(10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                InkWell(
                  onTap: _selectDate,
                  child: Row(
                    children: [
                      Text(DateFormat('yyyy.MM.dd').format(selectedDate)),
                      const Icon(Icons.arrow_drop_down)
                    ],
                  ),
                ),
              ],
            ),
            const SizedBox(height: 20,),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                InkWell(
                  onTap: _selectTime,
                  child: Row(
                    children: [
                      Text(DateFormat('yyyy.MM.dd').format(selectedDate)),
                      const Icon(Icons.arrow_drop_down)
                    ],
                  ),
                ),
                
              ],
            )
          ],
        ),
      ),
    );
  }
}